package com.lzy.huijinjiazu.mvp.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.di.component.DaggerFinanceDetailComponent;
import com.lzy.huijinjiazu.di.module.FinanceDetailModule;
import com.lzy.huijinjiazu.mvp.contract.FinanceDetailContract;
import com.lzy.huijinjiazu.mvp.presenter.FinanceDetailPresenter;
import com.lzy.huijinjiazu.mvp.ui.listener.ScrollViewListener;
import com.lzy.huijinjiazu.mvp.ui.widget.SlideScrollView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class FinanceDetailActivity extends BaseActivity<FinanceDetailPresenter> implements FinanceDetailContract.View, ScrollViewListener {


    @BindView(R.id.fl_title)
    FrameLayout mFlTitle;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.scrollView)
    SlideScrollView mScrollView;
    @BindView(R.id.tv_subscribe)
    TextView mTvSubscribe;

    private String mTitle;

    public static void start(Context context, String title) {
        Bundle bundle = new Bundle();
        bundle.putString("title", title);
        Intent intent = new Intent(context, FinanceDetailActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerFinanceDetailComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .financeDetailModule(new FinanceDetailModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_finance_detail; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        mTitle = getIntent().getStringExtra("title");
        mTvSubscribe.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
        initTitle();
    }

    private void initTitle() {
        mTvTitle.setText(mTitle);
        mFlTitle.setBackgroundResource(R.mipmap.bg_theme_title);
        mFlTitle.getBackground().setAlpha(0);
        mScrollView.setScrollViewListener(this);
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.setTitleBar(this, mFlTitle);
    }

    @Override
    public void onScrollChanged(SlideScrollView scrollView, int x, int y, int oldx, int oldy) {
        if (mFlTitle == null) {
            return;
        }
        if (y > 350) {
            mFlTitle.getBackground().setAlpha(255);
            return;
        }
        if (y <= 250 && y > 0) {
            mFlTitle.getBackground().setAlpha(y);
        }
    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
